package com.yuan.fruitweb.service.impl;

import com.yuan.fruitweb.dao.FruitDao;
import com.yuan.fruitweb.model.Fruit;
import com.yuan.fruitweb.service.FruitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author YuanYuemeng
 * @date 2020/11/23
 */

/**
 * 业务要做通知的事情
 */
@Service
public class FruitServiceImpl implements FruitService {
    private FruitDao fruitDao;
    //通过一个方法接收对象，实现约定好方法
    @Autowired
    public void setFruitDao(FruitDao fruitDao) {
        System.out.println("======================================"+fruitDao.getClass());
        this.fruitDao = fruitDao;
    }

    /**
     * 1.构造函数
     * 2.用javabean命名方法
     */

    @Override
    public boolean saveFruit(Fruit fruit) {
        return fruitDao.save(fruit);
    }

    @Override
    public void delFruitById(int id) {
        fruitDao.del(id);
    }

    @Override
    public Fruit findFruitById(int id) {
        return fruitDao.findById(id);
    }

    @Override
    public boolean updateFruit(Fruit fruit) {
        return fruitDao.update(fruit);
    }

    @Override
    public List<Fruit> findAllFruits() {
        return fruitDao.findAll();
    }

}
